﻿using Arch.EntityFrameworkCore.UnitOfWork;
using Common.Lib.Dto;
using Common.Lib.Parameter;
using Common.Lib.Service;
using Microsoft.AspNetCore.Mvc;
using Server.Todo.Context;
using Server.Todo.Service;

namespace Server.Todo.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ToDoController : ControllerBase
    {
        private readonly IToDoService toDoService;

        /// <summary>
        /// Todo Api控制器
        /// </summary>
        public ToDoController(IToDoService toDoService)
        {
            this.toDoService = toDoService;
        }

        [HttpGet]
        public async Task<ApiResponse> Get(int id)
        {
            return await toDoService.GetSingleAsync(id);
        }


        [HttpGet]
        public async Task<ApiResponse> GetAll([FromQuery] QueryParameter queryParameter)
        {
            return await toDoService.GetAllAsync(queryParameter);
        }


        [HttpGet]
        public async Task<ApiResponse> GetAllFilter([FromQuery] ToDoQueryParameter queryParameter)
        {
            return await toDoService.GetAllFilterAsync(queryParameter);
        }

        [HttpPost]
        public async Task<ApiResponse> Add([FromBody] ToDoDto model)
        {
            return await toDoService.AddAsync(model);
        }


        [HttpPost]
        public async Task<ApiResponse> Update([FromBody] ToDoDto model)
        {
            return await toDoService.UpdateAsync(model);
        }

        [HttpGet]
        public async Task<ApiResponse> Delete(int id)
        {
            return await toDoService.DeleteAsync(id);
        }

        [HttpGet]
        public async Task<ApiResponse> Summary()
        {
            return await toDoService.SummaryAsync();
        }
    }
}
